<template>
    <div class="order-details">
        <div class="status" :class="status=='已取消'?'status-cancel':''">
            订单状态： <span>待出库</span>
        </div>
        <div class="list-base bottom-ash-line">
            <normal-order-list-base :ibase="ibase" :dataset="dataset" />
            <div class="all-price" v-if="dataset.length > 1 && ibase.amount">订单合计:<span style="font-size:1.3rem;">￥<span style="font-size:1.9rem;">{{ibase.amount}}</span></span></div>
        </div>
        <!--        待完成/已取消 -->
<!--        <public-yellow v-show="item.status" class="order-public bottom-ash-line" :title="item.title" :weight="item.weight"-->
<!--                       :total="item.total"></public-yellow>-->
        <order-details-c
            :ordernumber="ibase.number"
            :createtime="item.createtime"
            :deposit="item.deposit"
            :collectPeople="item.collectPeople"
            :collectTime="item.collectTime"
            :cancelTime="item.cancelTime"
            :capital="item.capital"
            :mode="item.mode"
            :completeTime="item.completeTime"
            :item="item"
        />
    </div>
</template>

<script>
    import {Button,Dialog} from 'vant';
    import NormalOrderListBase from '../../components/currency/order-item/normal-list-base.vue';

    // import PublicYellow from '../../components/currency/order-list/public-price-yellow.vue';
    import OrderDetailsC from '../../components/currency/order-list/order-details.vue';

    export default {
        name: "order-details",
        components: {
            NormalOrderListBase: NormalOrderListBase,
            OrderDetailsC: OrderDetailsC, [Button.name]: Button,
            // PublicYellow: PublicYellow,
        },
        data() {
            return {
                item: {
                },
                status:'',
                ordernumber: '',
                ibase: {},
                dataset: [],
            }
        },
        mounted() {
            this.ordernumber = this.$route.query.ordernumber;
            this.getDetailsOrder();
        },
        methods: {
            getDetailsOrder() {
                var that = this;
                var url = '/api/home/order/getone';
                var param = {
                    ordernumber: this.ordernumber,
                    token: this.$store.state.options.user.token
                };
                this.$util.postRequestInterface(url, param, (res) => {
                    switch (res.data.status) {
                        case 1:
                            this.status = '待收取';
                            break;
                        case 2:
                            this.status = '待入库';
                            break;
                        case 3:
                            this.status = '待确认';
                            break;
                        case 4:
                            that.status = '待确认';
                            break;
                        case 5:
                            if (that.$store.state.options.user.oda.groupid==6){
                                that.status = '已确认';
                            } else {
                                that.status = '已完成';
                            }
                            break;
                        case 6:
                            if(that.$store.state.options.user.oda.groupid==5){
                                that.status = '已入库'
                            }else{
                                that.status = '已取消';
                            }
                            break;
                    }
                    var x = res.data;
                    var resDetail = x.detail;
                    for (let i of resDetail) {
                        that.dataset.push({
                            title: i.garbagename,
                            unit: i.danweiming,
                            number: parseInt(i.weighting_num),
                            // number: i.weighting_method == 1 ? parseInt(i.weighting_num) : '',
                            // weight: i.weighting_method == 0 ? i.weighting_num : '',
                            time: that.$moment(x.create_time * 1000).format('YYYY-MM-DD HH:mm:ss'),
                            price: parseFloat(i.price).toFixed(2),
                            isbaozhi:x.isbaozhi
                        });
                    }
                    that.ibase.number = x.ordernumber;
                    if (res.data.status!=2) {
                        that.ibase.amount =  x.price;
                    }
                    that.ibase.time =  that.$moment(x.create_time *1000).format('YYYY-MM-DD');
                    that.item = {
                        id:x.id,
                        status:x.status,
                        createtime:that.$moment(x.create_time *1000).format('YYYY-MM-DD HH:mm:ss'),
                        deposit:x.zancundian,
                        collectPeople: x.yewuyuan,
                        collectTime: "",
                        cancelTime: x.end_time?that.$moment(x.end_time *1000).format('YYYY-MM-DD HH:mm:ss'):'',
                        capital: x.paytype==0?'平台交易':'现场交易',
                        mode: x.delivery_method==0?'上门收取':'门店自送',
                        completeTime: x.end_time?that.$moment(x.end_time *1000).format('YYYY-MM-DD HH:mm:ss'):'',
                        userzhicheng:x.userzhicheng,
                        kuaijitime:x.kuaijitime ? that.$moment(x.kuaijitime *1000).format('YYYY-MM-DD HH:mm:ss') : ''
                    }
                    // that.item.recovery: '6.0',
                    //     total: '6.0',
                    //     collectTime: "2019-09-10 11:28:09",
                    //     cancelTime: "取消时间",
                })
            },
            eventClickCancelOrder(){
                Dialog.confirm({
                    title:'提示',
                    message:'是否确定要取消订单'
                }).then(()=>{
                    var url = '/api/home/order/cancel';
                    var param = {
                        ordernumber:this.ordernumber,
                        token:this.$store.state.options.user.token
                    };
                    this.$util.postRequestInterface(url,param,(res)=>{
                        if (res.code==200){
                            Dialog.alert({
                                title:'提示',
                                message:res.msg
                            }).then(()=>{
                                this.$router.go(-1)
                            })
                        }
                    })
                }).catch(()=>{

                })
            },
            eventClickConfirmOrder(){
                var url = '/api/home/order/confirm';
                var param = {
                    ordernumber:this.ordernumber,
                    token:this.$store.state.options.user.token
                };
                this.$util.postRequestInterface(url,param,(res)=>{
                    if (res.code==200){
                        Dialog.alert({
                            title:'提示',
                            message:res.msg
                        }).then(()=>{
                            this.$router.go(-1)
                        })
                    }
                })
            }
        },
    }
</script>

<style lang="scss" scoped>
    .order-details {
        .list-base {
            padding: 1rem;

            .all-price{
                color: #333333;
                width: 100%;
                text-align: right;
                margin-top: 2rem;

                span{
                    color: #FF0101;
                }
            }
        }
    }
</style>
